# Maintainer:  Dave Murphy <davem@devkitpro.org>
# Contributor: averne <averne381@gmail.com>
# Contributor: Cpasjuste <cpasjuste@gmail.com>

pkgbasename=libmpv
pkgname=switch-${pkgbasename}
pkgver=0.36.0
pkgrel=1
pkgdesc='Command line video player (library only)'
arch=('any')
url='https://mpv.io/'
license=('GPL')
options=(!strip libtool staticlibs)
source=("${pkgbasename}-${pkgver}.tar.gz::https://github.com/mpv-player/mpv/archive/v${pkgver}.tar.gz" "mpv.patch" "mp_image.patch")
sha256sums=(
  'SKIP'
  'SKIP'
  'SKIP'
)
makedepends=('switch-pkg-config' 'dkp-toolchain-vars')
depends=('switch-ffmpeg' 'switch-mesa')
groups=('switch-portlibs')

prepare() {
  cd mpv-$pkgver
  rm -rf audio/out/ao_hos.c
  rm -rf osdep/switch/sys/mman.h
  patch -Np1 -i "$srcdir/mpv.patch"
  patch -Np1 -i "$srcdir/mp_image.patch"
}

build() {
  cd mpv-$pkgver

  source /opt/devkitpro/switchvars.sh

  ./bootstrap.py
  export CFLAGS="$CFLAGS -D_POSIX_VERSION=200809L -DNDEBUG -I`pwd`/osdep/switch"
  LIBDIR=${PORTLIBS_PREFIX}/lib TARGET=aarch64-none-elf ./waf configure \
    --prefix="${PORTLIBS_PREFIX}" --disable-libmpv-shared \
    --enable-libmpv-static --disable-cplayer --disable-sdl2 --enable-hos-audio \
    --disable-iconv --disable-jpeg --disable-libavdevice --disable-debug-build
  sed -i 's/#define HAVE_POSIX 1/#define HAVE_POSIX 0/' build/config.h
  ./waf build
}

package() {
  cd mpv-$pkgver

  ./waf install --destdir=$pkgdir
}